#pragma once
#include "Singleton.h"
class HttpClient;
class HttpRequest;
class HttpResponse;
class TcpServer;
class TcpClient;

class NetworkManager : public Singleton<NetworkManager>
{
public:
	typedef void (*ResponseCallback)(HttpResponse* response);

public:
	NetworkManager();
	~NetworkManager();

	TcpServer* getServer() { return mTcpServer; }
	TcpClient* getClient() { return mTcpClient; }

	bool Init(int version = 0);
	void Update(float elapsedTime);
	void Destroy();

	bool CreateGame();
	void JoinGame(const char* host, int port);
	
	bool Request(HttpRequest* request, ResponseCallback callBack = NULL, bool autoDelete = true);

	void ClientToServer(const void* buff, size_t len, int channel = 0);
	void ServerToClient(const void* buff, size_t len, int channel = 0);

private:
	std::wstring mSessionKey;
	HttpClient* mHttpClient;
	TcpServer* mTcpServer;
	TcpClient* mTcpClient;
};
